package com.zzy.eventbus.subdemo;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.zzy.eventbus.subdemo.base.EventListener;
import com.zzy.eventbus.subdemo.base.SystemEvent;

/**
 * 成员删除事件监听器, 支持并发操作
 * @see MemberDeletedEvent
 * @see birdie-web下的EventBusTest
 * @author Jack
 *
 */
public class MemberDeletedEventListener implements EventListener{
    

    @Override
    @Subscribe
    @AllowConcurrentEvents   // Guava发布的事件默认不会处理线程安全的，但我们可以标注@AllowConcurrentEvents来保证其线程安全
    public void action(SystemEvent event) {
    	System.out.println(String.format("[MemberDeletedEventListener ] : event=%s", event.toString()));
        MemberDeletedEvent subEvent = (MemberDeletedEvent) event ;
        invoke(subEvent) ;
    }
    
    public void invoke(MemberDeletedEvent memberDeletedEvent) {
    	
    	memberDeletedEvent.setCmd(memberDeletedEvent.getCmd()-1);
        //...业务代码
        System.out.println(memberDeletedEvent.getCmd());

    }

}